/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package actions;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author mpastarini
 */
public abstract class Action implements Command {

    private ServletContext servletContext;

    protected Action() { }

    public void setServletContext(ServletContext sc) {
        this.servletContext = sc;
    }

    protected void gotoPage(String address, HttpServletRequest request, HttpServletResponse response) {

        try
        {
            RequestDispatcher dispatcher = this.servletContext.getRequestDispatcher(address);
            dispatcher.forward(request, response);
        }
        catch(ServletException e1)
        {
            System.out.print(e1.getMessage());
        }
        catch (IOException e2)
        {
            System.out.print(e2.getMessage());
        }

    }

    public abstract void execute(HttpServletRequest request, HttpServletResponse response);

}

